package org.shj.flink.source;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
import org.shj.flink.dto.SourceStaffDTO;

import java.util.Date;

/**
 * @author Shen Huang Jian
 * @date 2020-08-05 17:06
 */
public class MyCustomizeSource extends RichSourceFunction<SourceStaffDTO> {

    @Override
    public void open(Configuration parameters) throws Exception {
        super.open(parameters);
    }

    @Override
    public void close() throws Exception {
        super.close();
    }

    @Override
    public void run(SourceContext<SourceStaffDTO> sourceContext) throws Exception {
        int i = 0;
        while(i < 20){
            SourceStaffDTO staffDTO = new SourceStaffDTO();
            staffDTO.setName("name" + i);
            staffDTO.setBirthday(new Date());
            i++;
            try{
                Thread.sleep(1000);
            }catch(Exception e){

            }finally {
                sourceContext.collect(staffDTO);
            }
        }
    }

    @Override
    public void cancel() {

    }
}
